﻿using SD.DALFactory;
using SD.DataAccess.Repository;
using SD.Entity;
using SD.Entity.PageSearch;
using SD.Entity.SearchEntity;
using SD.Interface.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SD.Business.Service
{
    public class ActionInfoService : IActionInfoService
    {
        private ActionInfoRepository _actionInfoRepository;

        public ActionInfoService()
        {
            _actionInfoRepository = AbstractFactory.CreateActionInfoRepository();
        }

        public ActionInfo GetActionInfo(int Id)
        {
            return _actionInfoRepository.GetActionInfo(Id);
        }

        public int DeleteActionInfo(int Id)
        {
            return _actionInfoRepository.DeleteActionInfo(Id);
        }

        public List<ActionInfo> GetActionInfoList(ActionInfoSearch search)
        {
            return _actionInfoRepository.GetActionInfoList(search);
        }

        public PagedList<ActionInfo> QueryActionInfoList(ActionInfoSearch search, PageView view)
        {
            return _actionInfoRepository.QueryActionInfoList(search, view);
        }

        public int SaveActionInfo(ActionInfo actionInfo)
        {
            if (actionInfo.Id<=0)
            {
                return (int)_actionInfoRepository.Insert(actionInfo);
            }
            else
            {
                return (int)_actionInfoRepository.Update(actionInfo);
            }
        }

        //查询用户的菜单/功能权限
        public List<ActionInfo> QueryActionListByUserId(int userId, int actionTypeEnum)
        {
            return _actionInfoRepository.QueryActionListByUserId(userId, actionTypeEnum);
        }

        //判断用户是否有访问该方法的权限
        public bool HasAcccessAction(int userId, string controlName, string actionName, string method)
        {
            if (_actionInfoRepository.SelectUserActionCount(userId, controlName, actionName, method) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
